#include "../source/server.hpp"
using namespace std;
int main()
{
    tcpSocket c;
    if (!c.createClient("127.0.0.1", 8080))
    {
        lg(Error, "create client error");
        return 1;
    }
    int n = 5;
    while (n--)
    {
        std::string s = "hello lzz";
        if (c.send(s, false) == -1)
        {
            lg(Error, "send error");
            return 1;
        }
        lg(Info, "send data success!");
        string ans;
        ssize_t n = c.recv(&ans, 1024, false);
        cout << ans << endl;
        sleep(1);
    }
    n = 6;
    while (n--)
    {
        sleep(1);
    }
    n = 5;
    while (n--)
    {
        ssize_t ret;
        std::string s = "hello lzz";
        if ((ret = c.send(s, false)) == -1)
        {
            lg(Error, "send error");
            return 1;
        }
        lg(Info, "send data success!");
        string ans;
        if ((ret = c.recv(&ans, 1024, false)) == 0)
        {
            lg(Info, "server close the link, talk done");
            return 0;
        }
        cout << ans << endl;
        sleep(1);
    }
    return 0;
}